#
# @lc app=leetcode.cn id=46 lang=python
#
# [46] 全排列
#

# @lc code=start
class Solution(object):
    def permute(self, nums):
        """
        :type nums: List[int]
        :rtype: List[List[int]]
        """
        self.nums = nums
        self.result = []
        self.result_items = []
        self.loop()
        return self.result
    
    def loop(self):
        if len(self.result_items) == len(self.nums):
            self.result.append(self.result_items[:])
            return
        
        for i in range(len(self.nums)):
            if self.nums[i] in self.result_items:
                continue
            self.result_items.append(self.nums[i])
            self.loop()
            self.result_items.pop()
        
# @lc code=end

